using System;
using UnityEngine;

public class AIOperationManager : MonoBehaviour
{
    private void OnEnable()
    {
        EventCenter.GetInstance().AddEventListener<NextStep>(nameof(AIOperation),AIOperation);
    }

    private void OnDisable()
    {
        EventCenter.GetInstance().RemoveEventListener<NextStep>(nameof(AIOperation),AIOperation);
    }


    private void AIOperation(NextStep bestNextStep)
    {
        if (bestNextStep.Chess.chessDate.chessType == ChessType.Building)
        {
            //建筑生成兵
            ChessManager.GetInstance().InitChess(bestNextStep.soldierChessDate, bestNextStep.AttackPosition,ChessSide.Player2);
            EventCenter.GetInstance().EventTrigger("ReduceResources", ChessSide.Player2, bestNextStep.soldierChessDate.resourcesPoint);
        }
        else if (bestNextStep.Chess.chessDate.chessType == ChessType.Soldier &&
                 bestNextStep.MovePosition == bestNextStep.Chess.ChessDetail.Position)
        {
            //不能移动的士兵的攻击
            ChessManager.GetInstance().Damage(bestNextStep.MovePosition,bestNextStep.AttackPosition);
        }else if(bestNextStep.Chess.chessDate.chessType == ChessType.Soldier &&
                 bestNextStep.MovePosition == bestNextStep.AttackPosition)
        {
            //仅移动不攻击
            print("仅移动不攻击");
            ChessManager.GetInstance().MoveChess(bestNextStep.Chess.ChessDetail.Position, bestNextStep.MovePosition);
        }else if (bestNextStep.Chess.chessDate.chessType == ChessType.Soldier &&
                  bestNextStep.MovePosition != bestNextStep.AttackPosition)
        {
            //移动后攻击
            print("移动后攻击");
            ChessManager.GetInstance().MoveChess(bestNextStep.Chess.ChessDetail.Position, bestNextStep.MovePosition,bestNextStep.AttackPosition);
        }
    }
}
